import java.util.Scanner;

public class QuadraticEquation {
    public static void main(String[] args) {
        // 创建Scanner对象来接收用户输入
        Scanner scanner = new Scanner(System.in);

        // 用户输入系数a, b, c
        System.out.print("请输入系数a: ");
        double a = scanner.nextDouble();

        System.out.print("请输入系数b: ");
        double b = scanner.nextDouble();

        System.out.print("请输入系数c: ");
        double c = scanner.nextDouble();

        // 调用方法求解一元二次方程
        solveQuadratic(a, b, c);

        // 关闭Scanner
        scanner.close();
    }

    // 求解一元二次方程
    public static void solveQuadratic(double a, double b, double c) {
        // 计算判别式
        double discriminant = b * b - 4 * a * c;

        // 判断方程是否有实数解
        if (discriminant > 0) {
            // 两个不同的实数根
            double root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
            double root2 = (-b - Math.sqrt(discriminant)) / (2 * a);
            System.out.println("方程有两个不同的实数根: ");
            System.out.println("根1 = " + root1);
            System.out.println("根2 = " + root2);
        } else if (discriminant == 0) {
            // 一个实数根（重根）
            double root = -b / (2 * a);
            System.out.println("方程有一个实数根: ");
            System.out.println("根 = " + root);
        } else {
            // 没有实数根，只有复数根
            double realPart = -b / (2 * a);
            double imaginaryPart = Math.sqrt(-discriminant) / (2 * a);
            System.out.println("方程有两个复数根: ");
            System.out.println("根1 = " + realPart + " + " + imaginaryPart + "i");
            System.out.println("根2 = " + realPart + " - " + imaginaryPart + "i");
        }
    }
}